import {
  getCategoryList,
  postCategory,
  putCategory,
  deleteCategory,

  getProductList,
  postProduct,
  putProduct,
  deleteProduct,

  getProductAttrGroupList,
  postProductAttrGroup,
  putProductAttrGroup,
  deleteProductAttrGroup
} from '@/api/product'
import {
  getToken,
  setToken,
  removeToken
} from '@/utils/auth'
import {
  resetRouter
} from '@/router'

const getDefaultState = () => {
}

const state = getDefaultState()

const mutations = {
}

const actions = {
  getCategoryList({
    commit
  }, data) {
    return new Promise((resolve, reject) => {
      getCategoryList(data).then(response => {
        resolve(response)
      }).catch(error => {
        console.log(error)
        reject(error)
      })
    })
  },
  postCategory({
    commit
  }, data) {
    return new Promise((resolve, reject) => {
      postCategory(data).then(response => {
        resolve(response)
      }).catch(error => {
        console.log(error)
        reject(error)
      })
    })
  },
  putCategory({
    commit
  }, data) {
    return new Promise((resolve, reject) => {
      putCategory(data).then(response => {
        resolve(response)
      }).catch(error => {
        console.log(error)
        reject(error)
      })
    })
  },
  deleteCategory({
    commit
  }, data) {
    return new Promise((resolve, reject) => {
      deleteCategory(data).then(response => {
        resolve(response)
      }).catch(error => {
        console.log(error)
        reject(error)
      })
    })
  },
  getProductAttrGroupList({
    commit
  }, data) {
    return new Promise((resolve, reject) => {
      getProductAttrGroupList(data).then(response => {
        resolve(response)
      }).catch(error => {
        console.log(error)
        reject(error)
      })
    })
  },
  postProductAttrGroup({
    commit
  }, data) {
    return new Promise((resolve, reject) => {
      postProductAttrGroup(data).then(response => {
        resolve(response)
      }).catch(error => {
        console.log(error)
        reject(error)
      })
    })
  },
  putProductAttrGroup({
    commit
  }, data) {
    return new Promise((resolve, reject) => {
      putProductAttrGroup(data).then(response => {
        resolve(response)
      }).catch(error => {
        console.log(error)
        reject(error)
      })
    })
  },
  deleteProductAttrGroup({
    commit
  }, data) {
    return new Promise((resolve, reject) => {
      deleteProductAttrGroup(data).then(response => {
        resolve(response)
      }).catch(error => {
        console.log(error)
        reject(error)
      })
    })
  },
  getProductList({
    commit
  }, data) {
    return new Promise((resolve, reject) => {
      getProductList(data).then(response => {
        resolve(response)
      }).catch(error => {
        console.log(error)
        reject(error)
      })
    })
  },
  postProduct({
    commit
  }, data) {
    return new Promise((resolve, reject) => {
      postProduct(data).then(response => {
        resolve(response)
      }).catch(error => {
        console.log(error)
        reject(error)
      })
    })
  },
  putProduct({
    commit
  }, data) {
    return new Promise((resolve, reject) => {
      putProduct(data).then(response => {
        resolve(response)
      }).catch(error => {
        console.log(error)
        reject(error)
      })
    })
  },
  deleteProduct({
    commit
  }, data) {
    return new Promise((resolve, reject) => {
      deleteProduct(data).then(response => {
        resolve(response)
      }).catch(error => {
        console.log(error)
        reject(error)
      })
    })
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
